package com.lishe.lishe.lishe.module.myorder.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.lishe.lishe.R;

/**
 * 商品参数弹窗
 * @author Bin
 */
public class OrderInfoDialog extends Dialog implements View.OnClickListener {

	private Context context;
	private String mMoney;
	private String mGoodsMoney;
	private String mFreight;
	private String mCouponDecrease;
	private int mCouponListSize;
	private boolean mIsUseCoupon;

	public OrderInfoDialog(Context context, String money, String goodsmoney, String freight,
						   String couponDecrease, int couponSize, boolean isUseCoupon) {
		super(context, R.style.SimpleBottomDialog);
		this.context = context;
		this.mMoney = money;
		this.mGoodsMoney = goodsmoney;
		this.mFreight = freight;
		this.mCouponDecrease = couponDecrease;
		this.mCouponListSize = couponSize;
		this.mIsUseCoupon = isUseCoupon;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_orderinfo);
		Window dialogWindow = this.getWindow();
		dialogWindow.setGravity(Gravity.BOTTOM);

		Display display = dialogWindow.getWindowManager().getDefaultDisplay();
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		lp.width = display.getWidth();
		dialogWindow.setAttributes(lp);

		//设置点击Dialog外部任意区域关闭Dialog
		setCanceledOnTouchOutside(true);

		TextView integral =  findViewById(R.id.total_integral);
		integral.setText(String.format("%.0f", Double.parseDouble(mMoney) * 100) + "积分");
		TextView price =  findViewById(R.id.total_price);
		price.setText("¥" + mGoodsMoney);
		TextView freight =  findViewById(R.id.freight);
		TextView coupon = findViewById(R.id.coupon);
		TextView tvTip = findViewById(R.id.tip);
		View couponlayout = findViewById(R.id.coupon_layout);
		if (Double.parseDouble(mFreight) == 0) {
			freight.setText("包邮");
		} else {
			freight.setText("¥" + mFreight);
		}

		if (mCouponListSize == 0 || !mIsUseCoupon) {
			tvTip.setText(R.string.info_tip_no_coupon);
			couponlayout.setVisibility(View.GONE);
		} else {
			tvTip.setText(R.string.info_tip);
			coupon.setText("-¥" + mCouponDecrease);
		}

		findViewById(R.id.up).setOnClickListener(this);
		findViewById(R.id.up_area).setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		dismiss();
	}
}
